<?php

namespace app\api\service;

use think\facade\Db;

class SpikeSessionService
{

    /**
     * 获取所有场次及对应商品
     * */
    public static function getSpikeSessionList($store_id)
    {
        $time = date('Y-m-d');
        $spikeSessions = Db::name('spike_session')
                            ->alias('a')
                            ->field('a.id,a.session_title,a.end_time')
                            ->withAttr('end_time',function ($value){
                                return date('Y-m-d H:i:s',$value);
                            })
                            ->join('spike_meeting b','b.id=a.spike_meeting_id')
                            ->where(['b.activity_time' => $time,'b.store_id' => $store_id])
                            ->select();

        $spikeSessionsInfo = [];
        foreach ($spikeSessions as $v){
            $v['goods'] = SpikeGoodsService::getSpikeGoodsList($v['id'],true);
            $spikeSessionsInfo[] = $v;
        }


        return $spikeSessionsInfo;
    }


}